package com.gxl.butt.DAO.impl;

import com.gxl.butt.DAO.IReportInDayOfTopicDAO;
import com.gxl.butt.domain.ReportInDayOfTopic;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Repository;
import java.util.*;
/**
 * Created by GUOXIAOLIN on 2018/11/20.
 */
@Repository
public class ReportInDayOfTopicDAOImpl extends HibernateBaseDao<ReportInDayOfTopic> implements IReportInDayOfTopicDAO {

    @Override
    public List<ReportInDayOfTopic> getTopicReportInWeek(Long topicid) {
        Map<String, Object> values = new HashedMap();
        values.put("topicid", topicid);
        String hql = "SELECT * FROM report_in_day_of_topic dd WHERE dd.topicid = :topicid ORDER BY dd.inday DESC";
        List<Object>  objects = this.getListBySQL(hql, 0, 7, values);
        List<ReportInDayOfTopic> reportInDays = new ArrayList<ReportInDayOfTopic>();
        for (Object o : objects) {
            ReportInDayOfTopic reportInDayOfTopic = new ReportInDayOfTopic();
            Object[] oo = (Object[]) o;
            reportInDayOfTopic.setId(Long.valueOf(oo[0].toString()));
            reportInDayOfTopic.setCreateTime( oo[1].toString());
            reportInDayOfTopic.setGmtTime( oo[2].toString());
            reportInDayOfTopic.setInday(oo[3].toString());
            reportInDayOfTopic.setMqSum(Long.valueOf(oo[4].toString()));
            reportInDayOfTopic.setTopicid(Long.valueOf(oo[5].toString()));
            reportInDayOfTopic.setTopicname(oo[6].toString());
            reportInDays.add(reportInDayOfTopic);
        }
        if (reportInDays != null && reportInDays.size() > 0){
            return reportInDays;
        }
        return null;
    }

    @Override
    public Long saveDO(ReportInDayOfTopic ridt) {
        return (Long)this.save(ridt);
    }

    @Override
    public ReportInDayOfTopic getReportInDayOfTopicByTopicId(Long topicid) {
        String inday = String.valueOf(new Date().getTime()/1000/60/60/24);
        String hql = "from " + ReportInDayOfTopic.class.getName() + " do where do.topicid = " + topicid + "' and do.inday = '" + inday + "'";
        List<ReportInDayOfTopic> reportInDayOfTopics = this.getListByHql(hql);
        if (reportInDayOfTopics != null && reportInDayOfTopics.size() >0 ){
            return reportInDayOfTopics.get(0);
        }
        return null;
    }

}
